<template>
  <div class="container">
    <el-row class="">
      <el-col :span="16" align="left">
        <span style="line-height: 33px;">同意票数：{{ data.isNum }}票；不同意票数：{{ data.isNotNum }}票；评价得分:{{data.avg || 0}}分</span>
      </el-col>
      <el-col :span="8" align="right">
        <el-input v-model="data.params.expertname" placeholder="专家名称" style="width: 150px; margin-right: 15px"
          clearable />
        <el-button color="#626aef" @click="search()">筛选</el-button>
      </el-col>
    </el-row>

    <div class="banner">
      <!-- 列表 -->
      <Table class="table_" :operate="true" :tableArr="data.allTableData" :pagination="data.page" :columns="data.columns"
        :total="data.page.total" @delectTable="delectIds"></Table>
      <!-- 分页 -->
      <div class="example-pagination-block">
        <el-pagination :current-page="pagination.currentPage" :page-size="pagination.pageSize"
          :page-sizes="[10, 20, 30, 40, 50, 100]" background layout="prev, pager, next ,total,sizes,jumper"
          :total="data.page.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>

<script>
import { lookResult } from '@/views/project/api/projectApplication'
import SelectOption from '@/views/science/components/selectOption/index.vue'
import Table from '@/views/science/components/table/table.vue'
import {onMounted, reactive, ref,watch} from 'vue'
import request from "@/utils/request";
import * as proxy from "@/constants/proxy";
import {random} from "lodash";

export default {
  components: {
    Table,
    SelectOption,
  },
  props: {
    lookId: {
      type: String,
    },
    lookId1: {
      type: String,
    }
  },
  setup(props, { emit }) {

    // watch(
    //   () => props.lookId1,
    //   (props) => {
    //     tableList(props.lookId);
    //   })
    watch(() => props.lookId, (newValue) => {
      if (newValue) tableList(newValue)
    })

    const activeName = ref('first')
    const data = reactive({
      agreeWth: 0,
      unagreeWth: 0,

      allTableData: [],
      ids: [],
      columns: [
        {
          key: "expertname",
          width: 140,
          label: "专家"
        },
        {
          key: "status",
          width: 140,
          label: "状态"
        },
        {
          key: "expertconclusion",
          width: 140,
          label: "是否同意"
        },
        {
          key: "expertscore",
          width: 140,
          label: "打分情况"
        },
        {
          key: "expertopinion",
          width: 140,
          label: "审批意见"
        },

      ],
      page: { page: 1, limit: 10, total: 4 },
      orgAllList: [],//{itemText:1,itemValue:'1'}
      params: {
        expertname: "",
        current: 1,
        size: 10,
        id: '',
        id1: '',
      },
      isNum: 0,
      isNotNum: 0,
      avg:0,
    })
    //分页器信息
    const pagination = reactive({
      pageSize: 10,
      currentPage: 1,
    })
    //分页操作
    const handleSizeChange = (val) => {
      data.params.size = val
      tableList()
    }
    const handleCurrentChange = (val) => {
      data.params.current = val
      tableList()
    }
    // 发送请求
    onMounted(() => {
      search();
    });
    //搜索
    const search = () => {
      tableList();
    }
    //列表
    const tableList = async () => {
      data.params.id = props.lookId
      data.params.id1 = random(1, 1000000000);
      let ee =data.params;
      console.log(2222, data.params)
      let res = await lookResult(data.params)
/*      return request({
        url: proxy.CHECC_API_CMS + "/xmzx/kyxmlxps/zjcs/approval/preliminaryexamination/getExpertDetail",
        method: "post",
        params: {
          ee
        },
      }).then((res) => {
        let resData = res.data.data.records;*/
      if (res.data.success) {
        let records = res.data.data
        let list = res.data.data.records

        if (list.length > 0) {

          data.avg=list[0].avg

          data.isNum = list[0].isNum
         data.isNotNum = list[0].isNotNum

          list.map((item) => {
            if (item.expertscore) {
              item.status = "已评"
            } else {
              item.status = "待评"

            }

            if (item.expertconclusion == 2) {
              item.expertconclusion = "不同意"
            } else if (item.expertconclusion == 1) {
              item.expertconclusion = "同意"
            }else {
              item.expertconclusion = "待评价"
            }
          })


        }

        // list.forEach(e => {
        //   Reflect.set(e, 'conclusionName', (e.conclusion == 1 ? '同意' : e.conclusion == 2 ? '不同意' : ''))
        // });
        // data.allTableData = res.data.data.records
        data.allTableData = list
        console.log('data.allTableData', data.allTableData);

        data.page.total = records.total
      }
      // })
    }

    return {
      activeName,
      pagination,
      data,
      search,
      handleSizeChange,
      handleCurrentChange,
    }
  },
}
</script>

<style lang="scss">
.table_ {
  .el-pagination {
    display: none;
  }
}
</style>
<style lang="scss" scoped>
.example-pagination-block {
  margin-top: 15px;
  text-align: center;
}

:deep(.el-pagination .btn-next .el-icon) {
  margin: 0 auto;
}

:deep(.el-pagination .btn-prev .el-icon) {
  margin: 0 auto;
}

.container {
  background-color: white;
  padding: 20px;
}
</style>
